define(["jquery","bbcare","as/app/assessComm/assessComm.servers","as/app/assessComm/assessComm.ui"],function($,$bb,$servers,$ui){
	var event = {};

	/**
	 * 搜索成功后的回调函数
	 */
	var ajaxSearchCallBack = function(data,arg){
		$ui.result({
            "id":"assessCommSearchResult",
            "list":data.rows,
        });
        $("#assessCommSearchResult li").unbind("click");
        $("#assessCommSearchResult li").click(function(){
        	$("." + arg.className ).modal("hide");
        	var userId = $(this).attr("data-userId");
        	var info = $servers.getInfo(data.rows,userId);
        	$bb.openPage(arg.detailName,info);
        });
	}

	/**
	 * 根据手机号码或姓名进行搜索
	 */
	var onSearch = function(){
		var arg = $(this).data("arg");
		var text = $.trim( $("#searchText").val() );
		if( text ){
			var reg = /^1[3456789]\d{9}$/;
			var params = {"queueUserType":"0"};
			if( !reg.test(text) ){
				params.userName = text;
			}else{
				params.phoneNo = text;
			}
			$servers.ajaxSearch(params,ajaxSearchCallBack,arg);
		}else{
			$("#assessCommSearchResult").html('');
		}
	}

	/**
	 * 点击“新增”按钮，查询到患者，选择患者，进行评估
	 */
	event.onUserSearch = function(){
		var params = $(this).data("params");
		params.className = "assessListModal";
        $bb.modal({
            "className": params.className,
            "tit": params.title,
        },function(){
            $("." + params.className).modal("show");
            $ui.search({
                "dom":$("." + params.className + " .modal-body")
            });
            $("#searchText").unbind("input propertychange");
            $("#searchText").data("arg",params);
            $("#searchText").bind("input propertychange",onSearch);
            $("#searchBtn").unbind("click");
            $("#searchBtn").data("arg",params);
            $("#searchBtn").bind("click",onSearch);
        });
	}

	return event;
});